package at.guthy;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.URL;

import javax.swing.JFileChooser;
import javax.swing.JFrame;

import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.media.MediaFileSource;
import com.google.gdata.data.photos.AlbumEntry;
import com.google.gdata.data.photos.PhotoEntry;
import com.google.gdata.util.AuthenticationException;

public class BrowserWindow extends JFrame {
	public static JFileChooser fc = new JFileChooser();

	public BrowserWindow() {
		this.setTitle("Picasa Uploader");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		fc.setDialogTitle("JPG");

		fc.setApproveButtonText("Upload");
		fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fc.setMultiSelectionEnabled(true);
		fc.addActionListener(new BWActionListener());
		fc.setFileFilter(new MyFilter());

		this.getContentPane().add(fc);
	}
}

class MyFilter extends javax.swing.filechooser.FileFilter {
	public boolean accept(File file) {
		String filename = file.getName();
		if (file.isDirectory()) { return true; }
		return filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".JPG") || filename.endsWith(".JPEG");
	}

	public String getDescription() {
		return "JPEG Images (*.jpg, *.jpeg, *.JPG, *.JPEG)";
	}
}

class BWActionListener implements ActionListener {

	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getActionCommand() == JFileChooser.APPROVE_SELECTION) {

			JFileChooser src = (JFileChooser) arg0.getSource();
			Thread uploader = new UploaderThread(src.getSelectedFiles());
			uploader.start();
		}
		if (arg0.getActionCommand() == JFileChooser.CANCEL_SELECTION) {

		}
	}
}
